#!/bin/bash
#=================================================================
# date: 2021-06-25 14:59:28
# title: run_srs
# author: QRS
#=================================================================


CUR_FIL=${BASH_SOURCE[0]}
TOP_DIR=`cd $(dirname $CUR_FIL)/..; pwd`

VENDOR=hzcsai_com
PROJECT=frepai
# VERSION=srs.v4.0.167
VERSION=
if [[ x$VERSION == x ]]
then
    REPOSITORY="$VENDOR/$PROJECT"
else
    REPOSITORY="$VENDOR/$PROJECT:$VERSION"
fi

REDIS_ADDR=${REDIS_ADDR}
REDIS_PORT=${REDIS_PORT}
REDIS_PSWD=${REDIS_PSWD}

MINIO_SERVER_URL='frepai-1301930378.cos.ap-beijing.myqcloud.com'
MINIO_ACCESS_KEY='AKIDV7XjgOr42nMhneGdmiPs66rNioeFafeT'
MINIO_SECRET_KEY='d190cxQk0CHCtLXjhQt65tUr2yf7KI1V'

SS=app

cmd=""
arg=""

if [[ x$1 == xdev ]]
then
    arg="it --restart unless-stopped"
    shift
else
    cmd="-s $SS"
fi

__start__()
{
    docker container stop ${PROJECT}-srs ${PROJECT}-$SS 2>/dev/null
    docker container rm ${PROJECT}-srs ${PROJECT}-$SS 2>/dev/null

    docker run -d${arg} --name ${PROJECT}-$SS \
        --network host --restart unless-stopped \
        --env CANDIDATE=$(ifconfig eth0|grep 'inet '|awk '{print $2}') \
        --env REDIS_ADDR=${REDIS_ADDR} --env REDIS_PORT=${REDIS_PORT} --env REDIS_PSWD=${REDIS_PSWD} \
        --env PYTHONPATH=/frepai/codes/app \
        --env MINIO_SERVER_URL=$MINIO_SERVER_URL \
        --env MINIO_ACCESS_KEY=$MINIO_ACCESS_KEY \
        --env MINIO_SECRET_KEY=$MINIO_SECRET_KEY \
        --volume $TOP_DIR/app:/frepai/codes/app \
        --volume /frepai:/frepai\
        --volume $TOP_DIR/entrypoint.sh:/entrypoint.sh \
        $REPOSITORY $cmd
}
__start__

